import telnetAPI
import time
import argparse
import gpu_port_ip_map as Port_ip_map

def parse_args():
    parser = argparse.ArgumentParser(description="you should add those parameter") 
    parser.add_argument('--task_id')
    parser.add_argument('--switchIp',default="10.174.216.35")
    parser.add_argument('--source',default="192.168.1.4")      
    parser.add_argument('--destination',default="192.168.6.4")
    parser.add_argument('--inport', default="100GE1/0/1")
    parser.add_argument('--outport', default="100GE1/0/17")
    parser.add_argument('--aclId', default="410")
    parser.add_argument('--onlydel', default="False")
    args = parser.parse_args()       
    return args


def publish_acl_no_small_clos():
    #host_ip = '10.174.216.35'
    args = parse_args()
    host_ip = args.switchIp
    onlydel = args.onlydel
    username = 'admin1234'
    password = 'Oxc_2012'
    changepwd = 'N'

    commands = []
    commit = 'commit'
    quit = 'q'
    sy = "system-view"
    admin = "admin"
    port_mode = "port-mode port"
    confirm = "Y"

    acl_to_publish = {}
    #acl_to_publish["vs1"] = [("192.168.6.3", None, "100GE1/0/49", "100GE1/0/1", "410"), ("192.168.7.3", None, "100GE1/0/50", "100GE1/0/2", "411")]
    acl_to_publish["vs1"] = [(args.source, args.destination, args.outport, args.inport, args.aclId)]
    # print(host_ip,acl_to_publish,onlydel)

    task_int_acl_map = {}
    task_id = args.task_id

    commands.append(sy)
    to_del_acl_id = args.aclId
    for to_del_int in Port_ip_map.leaf_port_list:
            commands.append("interface %s" % to_del_int)
            commands.append("undo traffic-policy p%s inbound" %to_del_acl_id)
            commands.append(commit)
            commands.append(quit)

            commands.append("undo traffic policy p%s" %to_del_acl_id)
            commands.append(commit)

            commands.append("undo traffic behavior b%s" %to_del_acl_id)
            commands.append(commit)

            commands.append("undo traffic classifier c%s" %to_del_acl_id)
            commands.append(commit)

            commands.append("undo acl 3%s" %to_del_acl_id)
            commands.append(commit)
    commands.append(quit)
        
    telnet_client = telnetAPI.TelnetClient()
    if telnet_client.login_host(host_ip, username, password, changepwd):
        for cmd in commands:
            telnet_client.execute_some_command(cmd, interval=0.1)
    else:
        print("fail")
        time.sleep(3)

if __name__ == "__main__":
    publish_acl_no_small_clos()


